package ute.mvc.dto;

import java.util.ArrayList;
import java.util.List;

import ute.mvc.model.Question;

public class QuestionDTO {

	private String questionId;
	private String question;
	private List<String> answers;
	private String answer;
	private float point;
	private String rightAnswer;
	private int type;
	
	//Flag make true/false
	private boolean isCorrect = false;

	public QuestionDTO() {

	}

	public QuestionDTO(Question question) {
		this.questionId = question.getQuestionId();
		this.question = question.getQuestion();
		this.point = question.getPoint();
		this.rightAnswer = question.getRightAnswer();
		this.type = question.getType();
		this.parseAnswer(question.getAnswer());
	}

	public QuestionDTO(Question question, boolean flag) {
		this.questionId = question.getQuestionId();
		this.question = question.getQuestion();
		this.point = question.getPoint();
		this.rightAnswer = question.getRightAnswer();
		this.type = question.getType();
		this.answer = question.getAnswer();
	}

	public boolean isCorrect() {
		return isCorrect;
	}

	public void setCorrect(boolean isCorrect) {
		this.isCorrect = isCorrect;
	}

	public List<String> getAnswers() {
		return answers;
	}

	public void setAnswers(List<String> answers) {
		this.answers = answers;
	}

	public String getAnswer() {
		return answer;
	}

	public void setAnswer(String answer) {
		this.answer = answer;
	}

	private List<String> parseAnswer(String answer) {

		answers = new ArrayList<String>();
		if (type == 1) {
			return answers; // True false, don't use answer
		}
		String[] str = answer.split(";");
		for (int i = 0; i < str.length; i++) {
			answers.add(str[i].substring(2, str[i].length()));
		}
		return answers;
	}

	public String getQuestionId() {
		return questionId;
	}

	public void setQuestionId(String questionId) {
		this.questionId = questionId;
	}

	public String getQuestion() {
		return question;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	public float getPoint() {
		return point;
	}

	public void setPoint(float point) {
		this.point = point;
	}

	public String getRightAnswer() {
		return rightAnswer;
	}

	public void setRightAnswer(String rightAnswer) {
		this.rightAnswer = rightAnswer;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
}
